## Makefile Par4MSP

NAME	= par4msp
NAME_EXE	= run
SRC_DIR	= src
INC_DIR	= inc
SRC	= $(wildcard $(SRC_DIR)/*.cpp)
INCL	= $(wildcard $(INC_DIR)/*.h)
OBJ	= $(SRC:.cpp=.o)

INTEL = yes
DEBUG = no
PROFILING = no
DISP_VECTORIZE = no

ifeq ($(INTEL),yes)
	CXX     = icpc
	OMP	= -openmp
else
	CXX	= g++
	OMP	= -fopenmp
	LD_LIBRARY_PATH = /opt/mpfr/lib:/opt/gmp/lib:/opt/mpc/lib
endif

#Not yet implemented
#TBB	= -ltbb

MAKE    = make
RM      = /bin/rm -f

IPATH = -I./$(INC_DIR)

OBJOPT  = -O3 -Wall $(OMP) $(TBB)
EXEOPT  = -O3 -Wall $(OMP) $(TBB)

ifeq ($(INTEL),no)
	OPTIMIZE = -march=opteron -pipe
	OPTIMIZE = -march=native -mtune=native -pipe
else
	OPTIMIZE = -xsse4.2 -pipe -finline-functions -funroll-loops
	OPTIMIZE = -xhost
endif

ifeq ($(DEBUG),yes)
	DEBUGFLAGS	= -g
endif

ifeq ($(DEBUG),yes)
	ifneq ($(INTEL), yes)
		ifeq ($(DISP_VECTORIZE), yes)
			VECTORFLAGS = -ftree-vectorizer-verbose=2
		endif
	endif
endif

ifeq ($(PROFILING),yes)
	PROFFLAGS	= -pg
endif


CFLAGS  = $(OBJOPT) $(OPTIMIZE) $(IPATH) $(DEBUGFLAGS) $(VECTORFLAGS) $(PROFFLAGS)
LDFLAGS = $(EXEOPT) $(OPTIMIZE) $(LPATH) $(DEBUGFLAGS) $(VECTORFLAGS) $(PROFFLAGS)


# For Accelerer8 contest
NAME	= $(NAME_EXE)

all:    $(NAME)

$(NAME): $(OBJ)
	$(CXX) -o $@ $^ $(LDFLAGS)

$(NAME).o: $(INCL)

%.o: %.cpp
	$(CXX) -o $@ -c $< $(CFLAGS)

clean:
	$(RM) $(NAME) $(OBJ) $(INC_DIR)/*~ $(SRC_DIR)/*~


